import React, { Component } from 'react'
import './index.scss'
import axios from '../../components/axios'
import { Route ,Redirect,NavLink,Switch} from 'react-router-dom'
import pubsub from 'pubsub-js' 

export default class index extends Component {
    constructor(props){
        super(props)
        this.state={
            data:[],
            num:0,
            arr:[]
        }
    }
    componentDidMount(){
        pubsub.publish("component","标签")
        axios("tags"
        ).then(result=>{
            this.setState({data:result.data[0],num:result.data[0].length,arr:result.data[1]});
        }).catch(err=>{
            console.log(err);
        })
    }
    render() {
        console.log(this.state.data);
        return (
            <div className="tags-inner">
            <h2>Tags</h2>
            <p>目前{this.state.num}个标签</p>
            <nav>
                <ul>
                    {this.state.data.map((item,index)=>{
                        return (
                            <>
                                <li>
                                    <NavLink to={{pathname:"/search",state:{data:item.tags,type:"标签"}}}>{item.tags}</NavLink><span>{this.state.arr[index]}</span>
                                </li>
                            </>
                        )
                    })}
                </ul>
            </nav>
            </div>
        )
    }
}
